home *** CD-ROM | disk | FTP | other *** search
- Path: news.PBI.net!usenet
- From: mich@pbinet.com
- Newsgroups: comp.lang.c
- Subject: Re: Input into array of strings?
- Date: 9 Mar 1996 16:58:24 GMT
- Organization: Pacific Bell Internet Services
- Message-ID: <4hsdbg$efq@SNFC21_SRVR_WWW.PBI.net>
- References: <4hnv1e$o7n@rhea.glo.be>
- Reply-To: mich@pbinet.com
- NNTP-Posting-Host: ppp-5-36.rdcy01.pbinet.com
- X-Newsreader: IBM NewsReader/2 v1.03
-
- In <4hnv1e$o7n@rhea.glo.be>, sclaeys@glo.be (Sven Claeys) writes:
- >i've got a structure
-
- >struct ImmoData
- >{
- > char code[3][5];
- > ....
- >}....;
-
- >now i want to read data from a file with fgets(...) into this array.
-
- >I've tried
- > for (i=0; i<5; i++)
- > fgets(code[i],....);
- >or
- > for (i=0; i<5; i++)
- > fgets((char*) code[i], ...);
-
- >but none of these seem to work. As i'm debugging the first code is
- >read correct, but the second is appended to the first and is also read
- >into the second, and so on.
-
- >Could anyone help me with this strange phenomenon?
-
- You can probably fix this by insuring all your substrings (or lines, or whatever
- you care to call them) are null terminated. Allocate (or simply declare) a char
- string of usable length (80 will be adequate, I'm sure), load the string into the
- buffer from the file, strlen the string, add one to the index, append a '/0', and
- voila. viola. (?)
-
-